package com.fafa.thread;

public class Draw_Money {

    public static void main(String[] args) {
        for(int i = 0; i <= 2;i++){
            Thread thread = new Thread(new UserA());
            thread.setName( "线程" + (i));
            thread.start();
        }



    }
}


class UserA implements Runnable {
    public static int money = 10000;
    public static final Object obj = new Object();
    @Override
    public void run() {
        while (true) {
            synchronized (obj) {
                if (money <= 0) {
                    System.out.println("余额不足");
                    return;
                }
                money -= 1000;
                System.out.println(Thread.currentThread().getName() + "取出1000,卡内余额" + (money));

                try {
                    Thread.sleep(100);
                }
                catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}

